//
//  CZTabBarViewController.swift
//  sinaSwifWeiBo
//
//  Created by 张雪雪 on 16/2/24.
//  Copyright © 2016年 张雪雪. All rights reserved.
//

import UIKit

class CZTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        //如何做? 1.添加一个view 2.KVC
        //        tabBar = CZTabBar()
        // 名字不要和系统的一样
        let tabbar = CZTabBar()
        //如何做? 1.添加一个view 2.KVC
        //        tabBar = CZTabBar()
        // 名字不要和系统的一样
        setValue(tabbar, forKey: "tabBar")
        
        //实现点击事件
         tabbar.composeButton.addTarget(self, action: "showPublish", forControlEvents: UIControlEvents.TouchUpInside)
        
        //添加控制器
        addChildViewController()
        
        
     
    }

    //MARK:--按钮点击事件
    func showPublish(){
    
    let publish = CZPublishViewController()

        let nav = UINavigationController(rootViewController: publish)
        
        presentViewController(nav, animated: true) { () -> Void in
            
        }
    
    }
    
    
    ///addChildViewController -- 重载
    ///没有参数

    func addChildViewController() {
        
        addChildViewController(CZHomeViewController(), title: "主页", image: "tabbar_home")
        
        addChildViewController(CZMessageViewController(), title: "消息", image: "tabbar_message_center")
        
        addChildViewController(CZFindViewController(), title: "发现", image: "tabbar_discover")
        
        addChildViewController(CZSettingViewController(), title: "设置", image: "tabbar_profile")
        
        
        
    }
    
    
    func addChildViewController(childController: UIViewController,title:String,image:String) {
        //创建一个Home控制器
        //let home = CZHomeViewController()
        
        childController.title = title
        
        
        
        childController.tabBarItem.image = UIImage(named: image)
        
        childController.tabBarItem.selectedImage = UIImage(named: "\(image)_highlighted")
        
       // UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        addChildViewController(UINavigationController(rootViewController: childController))

    }
    
    
    
    
}
